<?php
/**
 * Created by PhpStorm.
 * User: boye009
 * Date: 2016/1/18
 * Time: 10:58
 */

namespace app\index\domain;

use app\index\domain\BaseDomain;
use app\shop\api\BannersApi;
use app\system\api\MemberApi;
use app\bbs\api\ForumThreadApi;
use app\bbs\api\ForumForumApi;
use app\bbs\api\ForumUserAdmingroupApi;
use app\bbs\api\ForumAttachmentApi;
use app\bbs\api\ForumSilentApi;

class FileDomain extends BaseDomain{

    protected $business_code = "file";

    /**
     * del thread pic
     * @return [type] [description]
     */
    public function delPic(){
        $this->apiReturnErr('接口以废弃');
        // if(IS_POST){
        //     $notes = "应用".$this->client_id."，调用图片删除服务";
        //     addLog("Picture/delete",$_GET,$_POST,$notes);
        //     $uid  = $this -> _post('uid',0,'uid缺失');
        //     $imgs = $this -> _post('imgs','','imgs不得为空');
        //     $tid  = $this -> _post('tid',0,'tid缺失');
        //     if(!$imgs) $this->apiReturnErr('imgs 为 null');

        //     //
        //     $r = apiCall(ForumThreadApi::GET_INFO,[['tid'=>$tid]]);
        //     if(!$r['status']) $this->apiReturnErr($r['info']);
        //     if(empty($r['info'])) $this->apiReturnErr('tid错误');
        //     $fid = intval($r['info']['fid']);
        //     $author_id = intval($r['info']['author_id']);
        //     //暂限时光机 - 9
        //     $r = apiCall(ForumForumApi::GET_FID_WITH_CHILD,[9]);
        //     if(!$r['status']) $this->apiReturnErr($r['info']);
        //     if(!in_array($fid,$r['info']))  $this->apiReturnErr('此接口暂限时光机板块使用!');
        //     //验证板块信息 - 返回是否审核
        //     if(0 ===$fid) $this->apiReturnErr('该帖板块非法');
        //     $r  = apiCall(ForumForumApi::CHECK_BLOCK,[$fid]);
        //     if(!$r['status']) $this->apiReturnErr($r['info']);
        //     $check = intval($r['info']);

        //     //验证用户板块权限
        //     //
        //     $r = apiCall(MemberApi::GET_INFO,[['uid'=>$uid]]);
        //     if(!$r['status']) $this->apiReturnErr($r['info']);
        //     if(empty($r['info'])) $this->apiReturnErr('uid错误');
        //     if($author_id == $uid){
        //         //用户为作者
        //         //是否为板块 或父板块 管理
        //         $r = apiCall(ForumUserAdmingroupApi::IS_ADMIN,[$uid,$fid]);
        //         if(!$r['status']) $this->apiReturnErr($r['info']);
        //         //用户是否禁言 - 非管理
        //         if(!$r['info']){
        //             $r = apiCall(ForumSilentApi::IS_SILENT,[$uid]);
        //             if(!$r['status']) $this->apiReturnErr($r['info']);
        //             if($r['info']) $this->apiReturnErr($r['info']);
        //         }
        //     }else{
        //        //用户是否有fid改帖权限
        //        $r = apiCall(ForumUserAdmingroupApi::HAS_POWER,[$uid,$fid,"ALLOW_EDIT_POST"]);
        //        if(!$r['status']) $this->apiReturnErr($r['info']);
        //        if(!$r['info']) $this->apiReturnErr('越权行为');
        //     }
        //     //仅删除帖子关联 - TODO 图片未使用删除
        //     $map = ['tid'=>$tid,'pid'=>0,'_string'=>'aid in ('.$imgs.')'];
        //     $r = apiCall(ForumAttachmentApi::DELETE,[$map]);
        //     if(!$r['status']) $this->apiReturnErr($r['info']);
        //     $this->apiReturnSuc('删除成功');
        // }else{
        //     $this->apiReturnErr('非法get请求');
        // }
    }
    /**
     * 获取app轮播图url
     */
    public function banner(){

        $this->checkVersion($this->api_ver);
        $notes = "应用" . $this->client_id ."调用轮播图获取接口";
        addLog("File/banner", $_GET, $_POST, $notes);

        if(IS_POST){
            $position = $this -> _post('position',"","缺少position参数");
            $map = ['position'=>$position];
            $result = apiCall(BannersApi::QUERY_NO_PAING,[$map,"sort asc",'url,url_type,notes,img,title']);
            if($result['status']){
                $this -> apiReturnSuc($result['info']);
            }else{
                $this -> apiReturnErr($result['info']);
            }
        }
    }
}